package jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by cyn on 2019/2/22.
 */
public class HelloServiceProxy implements InvocationHandler {

    private Object target;

    public Object bind(Object target){
        this.target = target;
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("################我是JDK动态代理########################");
        Object result = null;
        System.out.println("我准备说hello。");
        result = method.invoke(target,args);
        System.out.println("我说过hello了。");
        return result;
    }
}
